package be.xios.projectquiz.statuspanels;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;

import javax.swing.JPanel;

import be.xios.projectquiz.game.Game;

/// <summary>
/// Deze klasse is een jpanel waarop het status van het spel kan worden getekend
/// </summary>
/// <author>Sebastian Kubski</author>
@SuppressWarnings("serial")
public class GameStatusPanel extends JPanel {

	private String gameInfo[] = {"Type","Language","Started","Ended", "Maximum players","Connected players","Maximum rounds","Current round","Current vraag"};
	private String gameStatus[] = new String[9];
	private Color matrixKleur;
	
	public GameStatusPanel(Color matrixKleur) {
		this.matrixKleur=matrixKleur;
	}
	
	public void paintComponent(Graphics g) {
		super.paintComponent(g);
		this.setBackground(Color.BLACK);
		
		Graphics2D g2D=(Graphics2D) g;		
		g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);		

		g2D.setColor(matrixKleur);
		g2D.setFont(new Font("Arial", Font.BOLD, 12));
		
		g2D.drawRoundRect(2, 2, this.getWidth() - 5, this.getHeight() - 5, 5 , 5);
		
		for (int i = 0; i < gameInfo.length; i++) {
			int y = 10 + (i+1)*20;
			g.drawString(gameInfo[i] ,  7  , y);
			g.drawString(   ":"		 ,  150, y);
			if (gameStatus[i]==null) 
				gameStatus[i]="n/a";
			g.drawString(gameStatus[i], 155, y);
		}
	}

	/// <summary>
	/// Deze method updated de gameinfo
	/// </summary>
	/// <author>Sebastian Kubski</author>
	public void updateGameInfo(Game currentGame) {
		//Alle info updaten adhv currentGame
		gameStatus[0]= "" + currentGame.getGameName();
		gameStatus[1]= "" + selectTaal(currentGame.getLanguage());
		gameStatus[2]= "" + currentGame.isStarted();
		gameStatus[3]= "" + currentGame.isEnded();
		gameStatus[4]= "" + currentGame.getSpelers();
		gameStatus[5]= "" + currentGame.getPlayerList().size();
		gameStatus[6]= "" + currentGame.getRondes();
		gameStatus[7]= "" + currentGame.getHuidigeRonde(); 
		gameStatus[8]= "" + (currentGame.getHuidigeVraag() + 1);
		repaint();
	}
	
	/// <summary>
	/// Deze method zet de int om in een string
	/// </summary>
	/// <author>Sebastian Kubski</author>
	/// <author>Flemming Bosch: updated deze method</author>
	private String selectTaal(int taalID) {
		switch (taalID){
			case 1: 
				return "Nederlands";
			case 2:
				return "English";
			default:
				return "An error occured";
		}
	}
}